package com.ying.dogying.templates;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ying.dogying.entity.dto.ImPostDto;
import com.ying.dogying.service.ImPostService;
import com.ying.dogying.templates.common.TemplateDirective;
import com.ying.dogying.templates.common.TemplateDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ImPostTemplate extends TemplateDirective {

    @Autowired
    private ImPostService imPostService;

    @Override
    public String getName() {
        return "posts";
    }

    @Override
    public void execute(TemplateDto templateDto) throws Exception {
        Integer level = templateDto.getInteger("level");
        Integer pageNumber = templateDto.getInteger("pageNumber", 1);
        Integer pageSize = templateDto.getInteger("pageSize", 5);
        Long categoryId = templateDto.getLong("categoryId");

        IPage<ImPostDto> postList = imPostService.selectByParams(new Page(pageNumber, pageSize), categoryId, null, level, null, "CREATE_TIME");

        templateDto.put(RESULTS, postList).render();
    }
}
